<?php session_start(); $_SESSION['page'] = 'client';?>
<!doctype html public "-//W3C//DTD HTML 4.01//EN">

<?php
    $category = $_POST['category'];
    $searchtext = $_POST['searchtext'];
    $libraryNo = $_COOKIE['libraryNo'];
    require ('db_connection.php');

    $qcount = "SELECT MAX(userID) FROM tblclient";
    $rcount = mysql_query($qcount);
    while($row = mysql_fetch_array($rcount))
    {
      $ctr1 = $row['MAX(userID)'];
    }

    if($category == 'All')
    {

        $query = "SELECT * FROM tblclient WHERE libraryNo = '$libraryNo' AND libraryCardNo LIKE '%$searchtext' OR lastName LIKE '%$searchtext'";
    }
    else{
        $query = "SELECT * FROM tblclient WHERE $category LIKE '%$searchtext' AND libraryNo='$libraryNo'";
    }
    $result = mysql_query($query);
?>

<html>

   <head>
      <title>Client Result</title>
      <meta http-equiv="generator" content="PHP Designer 2005" />
      <style type="text/css">
        @import url(style.css);
      </style>
   </head>
   
   <script LANGUAGE=javascript>
    <!--
     function check()
     {
        if(document.search_form.searchtext.value=="" )
        {
          alert('Please fill the search box.');
          return false;
        }
        return true;
     }
     //-->
    </script>

   <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000" class=''>

    <table width='80%' align='center' class='content'>
        <tr><td colspan='2'><img src='images/banner.jpg'></td></tr>
        <tr><td align='right' colspan='2' class='logout'><?php require ('loginout.php');?></td></tr>
        <tr class='menuborder'><td width='90%'><img src='images/searchresult.png'></td><td><?php  require('buttons.php'); ?></td></tr>
        <tr><td colspan='2' class='bodyborder'>
        <form method='post' action='clientresult.php' name='search_form' onSubmit="return check();">
            <table align='center'>
            <tr><td height='30'></td></tr>
                <tr><td>Search By</td>
                    <td><select name='category'>
                        <option value='All'>All</option>
                        <option value='lastName'>Last Name</option>
                        <option value='libraryCardNo'>Library Card No.</option>
                        </select>
                    </td>
                    <td><input type='text' name='searchtext' size='40'></td>
                    <td><input type='submit'value='Search' class='tool'></td>
                </tr>
            <tr><td height='30'></td></tr>
            </table>
        </form>
        </td></tr>
        <tr><td colspan='2' class='bodyborder'>
        <?php echo "<form method='post' action='delete.php?page=client&clientCtr=$ctr1'";?>
        <table align='center' cellspacing='0' cellpadding='3' width='60%' >
        <?php
            $ctr = 1;
            echo "<tr align='center'><th colspan='4'>Search Result</th></tr>";
            echo "<tr><td height='15'></td></tr>";
            echo "<tr class='listtable'><th></th><th>User ID</th><th>Name</th><th>Address</th></tr>";
            //echo "<form method='post' action='delete.php?page=client&clientCtr=$ctr1'>";
            while ($row = mysql_fetch_array($result))
            {

              $lastName = $row['lastName'];
              $firstName = $row['firstName'];
              $userID = $row['userID'];
              $address = $row['address'];

              echo "<tr><td class='listborder'><input type='checkbox' name='ser[$ctr]' value='$userID'></td>";
              echo"<td class='listborder'><a href='clientdetail.php?userID=$userID'> $userID</td>";
              echo"<td class='listborder'>$lastName, $firstName</td>";
              echo"<td class='listborder'>$address</td></tr>";
              $ctr++;
            }
            echo "<tr><td height='15'></td></tr>";
            echo "<tr><td colspan='4' align='right'><input type='submit' value='Delete' class='tool'></td></tr>";
            echo "</form>";
        ?>
        </table>
            </td>
        </tr>
        <tr><td align='center' colspan='2'><?php require ('copyright.php')?></td></tr>
    </table>

   </body>
</html>



